/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

(function($){
    $.fn.extendButton = function(options) {

        var defaults = {
            click: function(){}
        };
        var myoptions = $.extend(defaults, options);

        return this.each(function() {
            var control = $(this);
            control.click(myoptions.click);
            control.hover(function() { control.addClass('ui-state-hover')}, function() { control.removeClass('ui-state-hover')})
        });
    };
    $.fn.extendButton.submit = function(element, url, params) {
                var f = $(element).parents('form')[0];
		if (!f) {
			f = document.createElement('form');
			f.style.display = 'none';
			element.parentNode.appendChild(f);
			f.method = 'POST';
		};
		if (typeof url == 'string' && url != '') {
			f.action = url;
		};
		var inputs = [];
		jQuery.each(params, function(name, value) {
			var input = document.createElement("input");
			input.setAttribute("type", "hidden");
			input.setAttribute("name", name);
			input.setAttribute("value", value);
			f.appendChild(input);
			inputs.push(input);
		});

		jQuery(f).trigger('submit');

		jQuery.each(inputs, function() {
			f.removeChild(this);
		});
    };
})(jQuery);

